function showPoliceVehicleSearch() {
	window.location.href = "showPoliceVehicleSearch.do";
}

function ajaxFindPoliceVehicleSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxPoliceVehicleSearchList.do",
		data : {
			deviceNum : $("#deviceNum").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listPoliceVehicleBox").html(msg);
		}
	});
}

function ajaxShowPoliceVehicleEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowPoliceVehicleEdit.do",
		data:{policeVehicleId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSavePoliceVehicle(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}


function ajaxSavePoliceVehicle(objDialog) {
	policeVehicleValidate();
	if ($("#frmPoliceVehicle").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSavePoliceVehicle.do",
				success: function (msg) {
					clearInput("#sltPoliceVehicle");
					showMessageDialog("保存警车信息","警车信息保存成功。",null,dialogType.info);
					ajaxFindPoliceVehicleSearchList();
				}
		};
		$("#frmPoliceVehicle").ajaxSubmit(options);
	}
}

function ajaxShowPoliceVehicleView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowPoliceVehicleView.do",
		data:{policeVehicleId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeletePoliceVehicleById(id) {
	var PoliceVehicleIds="";
	var sltPV = $("#listPoliceVehicleList tbody input:checked").length;
	if(id==null){
		$("#listPoliceVehicleList tbody input:checked").each(function(){ 
			PoliceVehicleIds += $(this).val()+";";
		});
		if(sltPV == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			PoliceVehicleIds = PoliceVehicleIds.substring(0, PoliceVehicleIds.length-1);
		} 
	}else{
		PoliceVehicleIds=id;
		sltPV = 1;
	}
	if( PoliceVehicleIds!=null){
		showMessageDialog("删除警车信息","确定要删除所选“"+sltPV+"”条警车信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeletePoliceVehicleByIds.do",
				data:{PoliceVehicleIds:PoliceVehicleIds},
				success:function(msg){
					ajaxFindPoliceVehicleSearchList();
					showMessageDialog("提示","警车信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function policeVehicleValidate(){
	$("#frmPoliceVehicle").validate({
		errorLabelContainer: $("#infoPoliceVehicle"),
		rules : {
			plateType : {
				required :true				
			},
			vehicleType : {
				required :true,
			},
			plateCode : {
				required :true				
			},
			ownedOrganization : {
				required :true,
			}
		},
		messages : {
			plateType  : {
				required :"请选择号牌种类！"
			},
			vehicleType : {
				required :"请选择车辆种类！"
			},
			plateCode  : {
				required :"请输入号牌号码！"
			},
			ownedOrganization : {
				required :"请选择所属单位！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}